package main

import "fmt"

func main() {
	nums := []int{6, 5, 4, 8}
	r := smallerNumbersThanCurrent(nums)
	fmt.Println(r)

}

func smallerNumbersThanCurrent(nums []int) []int {
	allList := make([]int, 101)
	for _, value := range nums {
		allList[value] = allList[value] + 1
	}
	last := 0
	for index := range allList {
		tmp := allList[index]
		allList[index] = last
		last = tmp + last
	}
	result := make([]int, len(nums))
	for i := 0; i < len(nums); i++ {
		result[i] = allList[nums[i]]
	}
	return result
}
